package main

import (
	"fmt"
	"sync"
)

func main() {
	// 基础示例
	fruitCount := map[string]int{
		"apple":  5,
		"banana": 3,
	}
	fruitCount["orange"] = 7
	delete(fruitCount, "banana")

	// 遍历
	for k, v := range fruitCount {
		fmt.Printf("%s: %d\n", k, v)
	}

	v, ok := fruitCount["apple"]
	if ok {
		fmt.Println(v)
	}

	myMap := make(map[string]string, 10)
	myMap["a"] = "b"
	myFuncMap := map[string]func() int{
		"funcA": func() int { return 1 },
	}
	fmt.Println(myFuncMap)
	f := myFuncMap["funcA"]
	fmt.Println(f())
	value, exists := myMap["a"]
	if exists {
		println(value)
	}
	for k, v := range myMap {
		println(k, v)
	}

	// 并发安全示例
	var safeMap sync.Map
	safeMap.Store("key1", "value1")
	if v, ok := safeMap.Load("key1"); ok {
		fmt.Println(v)
	}
}
